package com.zbcbms.controller;

import com.zbcbms.common.GetChartCommon;
import com.zbcbms.common.TableInitCommon;
import com.zbcbms.entity.tableData.BookTableData;
import com.zbcbms.service.impl.BookServiceImpl;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.chart.PieChart;
import javafx.scene.chart.StackedBarChart;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import java.net.URL;
import java.util.ResourceBundle;


/**
 * 表格加载控制类
 * @author fengq
 */
public class MainTableController implements Initializable {

    @FXML
    private TableView<BookTableData> searchTableView;
    @FXML
    private TableColumn<BookTableData, String> searchTableCode;
    @FXML
    private TableColumn<BookTableData, String> searchTableBookName;
    @FXML
    private TableColumn<BookTableData, String> searchTableAuthor;
    @FXML
    private TableColumn<BookTableData, String> searchTablePublishName;
    @FXML
    private TableColumn<BookTableData, String> searchTableYear;
    @FXML
    private TableColumn<BookTableData, String> searchTablePrice;
    @FXML
    private TableColumn<BookTableData, String> searchTableCategory;
    @FXML
    private TableColumn<BookTableData, String> searchTableStatus;

    @FXML
    private StackedBarChart<String,Number> bookTopStackedChart;
    @FXML
    private TextField searchText;


    @FXML
    private PieChart pieChartBookType;

    private GetChartCommon chartCommon=new GetChartCommon();

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        new TableInitCommon().homeTableInit(searchTableView,searchTableCode,searchTableBookName,searchTableStatus,
                searchTableAuthor,searchTablePublishName,searchTableYear,searchTablePrice,searchTableCategory,new BookServiceImpl().getBookTableViewData());
        bookTopStackedChart.setData(chartCommon.getBorrowTopStackedBarChart());
        pieChartBookType.setData(chartCommon.getBookTypeChartData());
    }

    @FXML
    public void searchBtnAction(){
        String text = searchText.getText();
        new TableInitCommon().homeTableInit(searchTableView,searchTableCode,searchTableBookName,searchTableStatus,
                searchTableAuthor,searchTablePublishName,searchTableYear,searchTablePrice,searchTableCategory,
                new BookServiceImpl().getBookVoByKeyWord(text));
    }


}
